package com.hmall.item.interceptor;

import com.hmall.item.util.ThreadLocalUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 定义拦截器
 */
@Component
@Slf4j
public class MyIntercpetor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
//        Long header = Long.valueOf(request.getHeader("authorization"));
//        ThreadLocalUtil.setUserId(header);
//        System.out.println("用户id为: "+header);
        return true;
    }
}
